package com.zs.leymovie.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.lidroid.xutils.BitmapUtils;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.zs.leymovie.R;
import com.zs.leymovie.bean.PromotionDataEntity;

import java.util.List;

/**
 * Created by Administrator on 2015/8/22.
 */
public class ActivityPtrAdapter extends AppAdapter<PromotionDataEntity> {
    private BitmapUtils bitmapUtils;
    public ActivityPtrAdapter(List<PromotionDataEntity> list, Context context,BitmapUtils bitmapUtils) {
        super(list, context);
        this.bitmapUtils = bitmapUtils;
    }

    @Override
    public View getItemView(int position, View convertView, ViewGroup parent) {
        ViewHolder vh;
        if(convertView == null){
            convertView = inflater.inflate(R.layout.activy_ptritem_layout,parent,false);
            vh = new ViewHolder(convertView);
            convertView.setTag(vh);
        }else{
            vh = (ViewHolder) convertView.getTag();
        }
         vh.name.setText(list.get(position).getPromotion_name());
         vh.time.setText(list.get(position).getStart_date()+" - "+list.get(position).getEnd_date());
         bitmapUtils.display(vh.img,list.get(position).getPromotion_img_url());
        return convertView;
    }

    public static class ViewHolder{
        @ViewInject(R.id.activity_name)
        private TextView name;
        @ViewInject(R.id.activity_time)
        private TextView time;
        @ViewInject(R.id.activity_image)
        private ImageView img;
        public ViewHolder(View itemView){
            ViewUtils.inject(this,itemView);
        }
    }
}
